6dd7cd4da7412656b63960669958c97d743d1dea,epoxy-adapter/src/main/java/com/airbnb/epoxy/DiffHelper.java,DiffHelper,collectRemovals,#List#,275

Before Change


   * @return The number of items removed
   */
  private int collectRemovals(List<UpdateOp> result) {
    int removalCount = 0;
    UpdateOp lastRemoval = null;
    for (ModelState state : oldStateList) {
      // Update the position of the item to take into account previous removals,
      // so that future operations will reference the correct position
      state.position -= removalCount;

      // This is our first time going through the list, so we
      // look up the item with the matching id in the new
      // list and hold a reference to it so that we can access it quickly in the future
      state.pair = currentStateMap.get(state.id);
      if (state.pair != null) {
        state.pair.pair = state;
        continue;
      }

      int indexToRemove = state.position;
      if (lastRemoval != null && lastRemoval.positionStart == indexToRemove) {
        lastRemoval.itemCount++;
      } else {
        if (lastRemoval != null) {
          result.add(lastRemoval);
        }
        lastRemoval = UpdateOp.instance(UpdateOp.REMOVE, indexToRemove);
      }
      removalCount++;
    }

    if (lastRemoval != null) {
      result.add(lastRemoval);
    }

    return removalCount;

After Change


   * walk through the {@link #oldStateList} and check for items that don't exist in the new list.
   * Walking through it in order makes it easy to batch adjacent removals.
   */
  private void collectRemovals(UpdateOpHelper helper) {
    for (ModelState state : oldStateList) {
      // Update the position of the item to take into account previous removals,
      // so that future operations will reference the correct position
      state.position -= helper.getNumRemovals();

      // This is our first time going through the list, so we
      // look up the item with the matching id in the new
      // list and hold a reference to it so that we can access it quickly in the future
      state.pair = currentStateMap.get(state.id);
      if (state.pair != null) {
        state.pair.pair = state;
        continue;
      }

      helper.remove(state.position);
    }
  }